import { fa } from "element-plus/es/locales.mjs";

/*
 * @Author: wangyongcun@persagy.com
 * @Date: 2025-03-08 15:55:07
 * @LastEditTime: 2025-03-11 19:16:11
 * @FilePath: \vite-admin\src\router\guard\auth.ts
 * @Description: 鉴权
 *
 */

export function createAuthGuard(router: Router) {
  router.beforeEach((to, _, next) => {
    const { requireAuth } = to.meta;
    const { userInfo } = useUserStore();
    // 如果不需要鉴权
    if (requireAuth === false || to.path === '/login' || userInfo) {
      next();
    } else {
      next('/login');
    }
  });
}
